package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Dept;
import cn.wolfcode.domain.Emp;
import cn.wolfcode.domain.Result;
import cn.wolfcode.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping
    public Result selAll(){
        //调用Service
        log.info("部门信息查询");
        List<Dept> deptList=deptService.selAll();
        return Result.success(deptList);
    }
    @DeleteMapping("/{id}")
    public Result delById(@PathVariable Long id){
        log.info("部门删除:id:{}",id);
        deptService.delById(id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Dept dept){
        log.info("部门新增：{}",dept);
        deptService.add(dept);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result selById(@PathVariable Long id){
        log.info("部门根据id:{} 查询",id);
        Dept dept=deptService.selById(id);
        return Result.success(dept);
    }
    @PutMapping
    public Result updateId(@RequestBody Dept dept){
        log.info("部门修改{}",dept);
        deptService.updateId(dept);
        return Result.success();
    }
}
